from scrapyProject.spiders.fang.fangDataBase import fangDataBase
from scrapyProject.spiders.fang.Items import CatalogItem, HouseInfoItem

class ItemDataBase():
    def open_spider(self, spider):
        self.m_dataHandle = fangDataBase()

    def process_item(self, item, spider):
        #保存数据
        if isinstance(item, CatalogItem):
            item["id"]=self.m_dataHandle.insertAndUpdateCatalog(
                item["CityName"], item["ProvinceName"],item["urlNewHouse"],
                item["urlSencondHandHouse"], item["urlRentalhousing"]
            )
        # 插入数据
        elif isinstance(item, HouseInfoItem) == True:
            self.m_dataHandle.insertAnddUpdateHouseInfo(
                item["name"], item["address"],item["tele"],item["housetype"],item["characteristic"],
                item["collecttime"], item["idCatalog"], item["price"], item["type"]
            )
        return  item
